package com.lbjhan.rpc.consumer.controller;

import com.lbjhan.rpc.api.UserService;
import com.lbjhan.rpc.consumer.anno.RpcAutowire;
import com.lbjhan.rpc.pojo.ObjectVO;
import com.lbjhan.rpc.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("clientQuery")
public class ClientController {

    @RpcAutowire
    UserService userService;

    @RequestMapping("findUserById")
    @ResponseBody
    public User findUserById(Integer id){
        System.out.println("findUserById : ");
        User user = userService.getById(id);
        System.out.println(user);
        return user;
    }

    @RequestMapping("modifyNameById")
    @ResponseBody
    public ObjectVO modifyNameById(Integer id, String name){
        User user = userService.changeNameById(id, name);
        if(user == null)
            return new ObjectVO(404, "修改name失败，未查到id为"+id+"的User");
        else
            return new ObjectVO(200, user);
    }
}
